var ID;
var name;
var wxNum;
var toquestion=1;
Page({
  data:{
    experts:"",
    NoshowQue:'display',
    showQue:'none',
  

  },
  Login: function () {
    var that = this;

    wx.checkSession({
      success: function () {
        wx.getStorage({
          key: 'login_uuId',
          success: function (res) {

            wxNum = res.data;
            wx.request({
              url: "https://www.liuxuanlong.xyz/fenda/wx/checkLoginTime",
              data: {
                login_uuId: wxNum
              },
              success: function (res) {
                if (res.data == 'error') {
                  that.tologin();
                }
                else {
                  that.check_black();
                }
              },
            })

          },
        })

      },
      fail: function () {
        console.log("fail")
        that.tologin();
      },

    })


    //

  },

  tologin: function () {
    wx.showToast({
      title: '登录中',
      icon: 'loading',
      duration: 1000
    })
    var that = this;
    wx.login({
      success: function (res) {
        if (res.code) {
          //发起网络请求
          wx.request({
            url: 'https://www.liuxuanlong.xyz/fenda/wx/wxLoginFalv',
            data: {
              code: res.code
            },
            success: function (res) {
              console.log("return" + res.data);
              wx.setStorage({
                key: "login_uuId",
                data: res.data
              });

              wxNum = res.data;
              that.check_black();
            }
          })
        } else {
          console.log('获取用户登录态失败！' + res.avatarUrl)
        }
      }
    })
  },
  check_black: function () {
   
    wxNum = wx.getStorageSync('login_uuId');
    wx.request({
      url: 'https://www.liuxuanlong.xyz/fenda/wx/checkUserIsBlack',
      data: {
        wxNumber: wxNum
      },
      success: function (res) {
        if (res.data === '是') {
          wx.showModal({
            title: '',
            content: '检测您发表了不正当言论，已限制您进行提问。请联系平台人员已解除限制',
          })
         
        }
        else {
         
          wx.navigateTo({
            url: 'information/information?id=' + ID + '&name=' + name,
            success: function (res) {
              // success
              toquestion = 1;
            },
            fail: function () {
              // fail
            },
            complete: function () {
              // complete
            }
          })
        }
      },

    })


  },
  one:function(e){
    wx.showToast({
      title: '加载中',
      icon: 'loading'
    })
    var index = e.currentTarget.id;
    ID = this.data.experts[index].id;
    name=this.data.experts[index].name;
    console.log(ID,name);
    if(toquestion==1){
    this.Login();
    toquestion=0;
    }
    
   
    
    
  },
  Loadexperts:function(){
    var that=this;
    wx.request({
      url: "https://www.liuxuanlong.xyz/fenda/wx/findMaster",
      data:{
        id: getApp().globalData.hospitalId
      },
      method:"GET",
      success:function(res){
        //获取专家信息
        
        console.log(res.data,'专家列表')
        that.setData(
          {
            experts:res.data,
            NoshowQue:'none',
            showQue:'display'
          }
        );
      },
      fail:function(){
        //提示断网
      },
    })
  },
  onLoad:function(options){
      var that=this;
    // 生命周期函数--监听页面加载
      this.Loadexperts();
    
  },

})